#include <QPainter>
#include "include/CSplashScreen.h"
#include <QDesktopWidget>
#include <QApplication>


////////////////////////////////////////////////////////////////////////////
CSplashScreen::CSplashScreen(const QPixmap& thePixmap)
	: QFrame(0, Qt::FramelessWindowHint|Qt::WindowStaysOnTopHint)
	, itsPixmap(thePixmap)
{
	setAttribute(Qt::WA_TranslucentBackground);
	setFixedSize(itsPixmap.size());
	int x, y;
	int screenWidth;
	int screenHeight;

	int WIDTH = 413;
	int HEIGHT = 276;

	QDesktopWidget *desktop = QApplication::desktop();

	screenWidth = desktop->width();
	screenHeight = desktop->height();

	x = (screenWidth - WIDTH) / 2;
	y = (screenHeight - HEIGHT) / 2;

	this->setGeometry(x, y, WIDTH, HEIGHT);
	this->setFixedSize(WIDTH, HEIGHT);

};

////////////////////////////////////////////////////////////////////////////
void CSplashScreen::clearMessage()
{
	itsMessage.clear();
	repaint();
}

////////////////////////////////////////////////////////////////////////////
void CSplashScreen::showMessage(const QString& theMessage, int theAlignment/* = Qt::AlignLeft*/, const QColor& theColor/* = Qt::black*/)
{
	itsMessage  = theMessage;
	itsAlignment = theAlignment;
	itsColor  = theColor;
	repaint();
}

////////////////////////////////////////////////////////////////////////////
void CSplashScreen::paintEvent(QPaintEvent*)
{
	QRect aTextRect(rect());
	aTextRect.setRect(aTextRect.x() + 5, aTextRect.y() + 5, aTextRect.width() - 10, aTextRect.height() - 10);

	QPainter aPainter(this);
	aPainter.drawPixmap(rect(), itsPixmap);
	aPainter.setPen(itsColor);
	aPainter.drawText(aTextRect, itsAlignment, itsMessage);
}
